package com.lianzhihui.romeex.mvp.model;

import android.content.Context;

import com.lianzhihui.romeex.bean.TradeRecordBean;
import com.lianzhihui.romeex.net.APIConstant;
import com.lianzhihui.romeex.net.HttpManager;
import com.lianzhihui.romeex.net.HttpManagerCallback;
import com.lianzhihui.romeex.net.ResultData;
import com.lianzhihui.romeex.utils.GsonUtil;
import com.zhouyou.http.exception.ApiException;
import com.zhouyou.http.model.HttpParams;

/**
 * Description:
 * Author: RAMON
 * CreateDate: 2020/11/12 6:59 PM
 * UpdateUser:
 * UpdateDate:
 * UpdateRemark:
 * Version:
 */
public class TradeDetailsModel {

    Context context;
    TradeDetailsInterface callback;

    public TradeDetailsModel(Context context, TradeDetailsInterface callback) {
        this.context = context;
        this.callback = callback;
    }

    public void getTradeDtails(String hashcode) {

        HttpParams params = new HttpParams();
        params.put("transactionHashcode", hashcode);
        new HttpManager(context, new HttpManagerCallback() {
            @Override
            public void onSuccess(ResultData o) {
                if (o.getCode() == 200) {
                    TradeRecordBean.DetailBean bean = GsonUtil.GsonToBean(o.getData(), TradeRecordBean.DetailBean.class);
                    callback.onGetTradeDetails(bean);
                }
            }

            @Override
            public void onError(ApiException e) {
                callback.onGetTradeDetailsFail(e.getMessage());
            }
        }).post(APIConstant.TRADE_DEATAILS, params);

    }

}
